package me.zhengjie.modules.web.service.poster.impl;

import cn.hutool.core.collection.CollectionUtil;
import me.zhengjie.constant.ConstantUtils;
import me.zhengjie.modules.system.service.PosterService;
import me.zhengjie.modules.system.service.dto.PosterDto;
import me.zhengjie.modules.system.service.dto.PosterQueryCriteria;
import me.zhengjie.modules.web.domain.poster.PosterResponse;
import me.zhengjie.modules.web.service.poster.ISharePosterService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;

@Service
public class SharePosterServiceImpl implements ISharePosterService {

    @Autowired
    private PosterService posterService;
    @Override
    public List<PosterResponse> posterList(Integer type) {
        PosterQueryCriteria criteria = new PosterQueryCriteria();
        criteria.setPosterType(type);
        criteria.setStatus(ConstantUtils.Valid);
        List<PosterDto> posterDtos = posterService.queryAll(criteria);
        if (CollectionUtil.isEmpty(posterDtos)){
            return null;
        }
        List<PosterDto> collect = posterDtos.stream().sorted(Comparator.comparing(PosterDto::getId, Comparator.reverseOrder())).collect(Collectors.toList());
        List<PosterResponse> responseList = new ArrayList<>();
        collect.forEach(s -> {
            PosterResponse resp = new PosterResponse();
            resp.setUrl(s.getPosterUrl());
            responseList.add(resp);
        });
        return responseList;
    }
}
